﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Sausage.Common;
using Sausage.Common.Pinyin;
using Sausage.Web.Code;

namespace Sausage.Web.Controllers
{
    /// <summary>
    /// 汉字转拼音控制器
    /// </summary>
    /// <remarks></remarks>
    public class PinYinController : Controller
    {
        /// <summary>
        /// 将指定的汉字转化为拼音。
        /// </summary>
        /// <param name="source">要转换的汉字。</param>
        /// <returns>将指定的汉字转换而成的拼音。</returns>
        /// <remarks></remarks>
        [HttpGet]
        [JsonHandleError]
        [PermissionCheckAttribute("*")]
        public JsonResult Convert(string source)
        {
            //用于保存拼音
            string pinyin = string.Empty;

            //判断源字符串是否有效
            if (!string.IsNullOrEmpty(source))
            {
                //转换拼音
                pinyin = PinYinConverter.ConvertToPinYin(source);
            }

            //返回结果
            return Json(new JsonResultViewModel { success = true, message = "转换成功！", data = pinyin },
                        JsonRequestBehavior.AllowGet);
        }
    }
}
